home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / obrn-a_1.5_src.lha / oberon-a / source3.lha / Source / OL / OLSettings.mod < prev    next >
Encoding:
Text File  |  1995-01-26  |  6.6 KB  |  251 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: OLSettings.mod $
  4.   Description: Preferences settings for OL
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 1.3 $
  8.       $Author: fjc $
  9.         $Date: 1995/01/26 02:07:58 $
  10.  
  11.   Copyright © 1995, Frank Copeland.
  12.   This file is part of OL
  13.   See OL.doc for conditions of use and distribution.
  14.  
  15.   Log entries are at the end of the file.
  16.  
  17. *************************************************************************)
  18.  
  19. <* STANDARD- *> <* MAIN- *> <* INITIALISE- *>
  20.  
  21. MODULE OLSettings;
  22.  
  23. IMPORT SYS := SYSTEM, d := Dos, du := DosUtil, e := Exec, str := Strings;
  24.  
  25. (* Preferences settings *)
  26.  
  27. CONST
  28.  
  29.   StrLen = 128;                      (* Max length of a string.         *)
  30.   OLPF = 04F4C5046H; (* "OLPF" *)    (* Tag for preferences file.       *)
  31.   PrefsVersion = 1;                  (* Preferences file version.       *)
  32.  
  33. TYPE
  34.  
  35.   STR = ARRAY StrLen OF CHAR;
  36.  
  37. CONST
  38.  
  39.   (* Currently supported linkers *)
  40.   ALink* = 0; BLink* = 1; DLink* = 2;
  41.  
  42. VAR
  43.   SymSearch*,                        (* Search paths for symbol files.  *)
  44.   ObjSearch*,                        (* Search paths for object files.  *)
  45.   WithPath*,                         (* Directory to write .with files. *)
  46.   ProgPath*,                         (* Directory to write programs.    *)
  47.   SymExt*,                           (* Extensions for symbol files.    *)
  48.   ObjExt*,                           (* Extensions for object files.    *)
  49.   WithExt*,                          (* Extension for .with files.      *)
  50.   LinkCmd*,                          (* Path of linker.                 *)
  51.   LinkArgs*                          (* Command line args for linker.   *)
  52.     : STR;
  53.   Verbose*,                          (* Verbose output.                 *)
  54.   MakeIcons*                         (* Create icons for with files and
  55.                                      ** programs.
  56.                                      *)
  57.     : BOOLEAN;
  58.   WithFmt*                           (* Format of .with files.          *)
  59.     : LONGINT;
  60.  
  61. CONST
  62.  
  63.   defSymSearch = "";
  64.   defObjSearch = "";
  65.   defWithPath  = "";
  66.   defProgPath  = "";
  67.   defSymExt    = ".sym";
  68.   defObjExt    = ".obj";
  69.   defWithExt   = ".with";
  70.   defLinkCmd   = "";
  71.   defLinkArgs  = "";
  72.   defVerbose   = TRUE;
  73.   defMakeIcons = FALSE;
  74.   defWithFmt   = BLink;
  75.  
  76. (*------------------------------------*)
  77. PROCEDURE Init ();
  78.  
  79. BEGIN (* Init *)
  80.   SymSearch := defSymSearch;
  81.   ObjSearch := defObjSearch;
  82.   WithPath := defWithPath;
  83.   ProgPath := defProgPath;
  84.   SymExt := defSymExt;
  85.   ObjExt := defObjExt;
  86.   WithExt := defWithExt;
  87.   LinkCmd := defLinkCmd;
  88.   LinkArgs := defLinkArgs;
  89.   Verbose := defVerbose;
  90.   MakeIcons := defMakeIcons;
  91.   WithFmt := defWithFmt;
  92. END Init;
  93.  
  94. (*------------------------------------*)
  95. PROCEDURE LoadPrefs* ( fileName : ARRAY OF CHAR ) : BOOLEAN;
  96.  
  97.   VAR
  98.     pf   : d.FileHandlePtr;
  99.     s    : ARRAY StrLen OF CHAR;
  100.     dir  : ARRAY 3 OF e.LSTRPTR;
  101.     tag  : LONGINT; i, ver : INTEGER;
  102.     c    : CHAR;
  103.  
  104.   PROCEDURE Read ( fh : d.FileHandlePtr; VAR x : SYS.BYTE );
  105.     VAR i : LONGINT;
  106.   BEGIN (* Read *)
  107.     i := d.FGetC (fh); x := CHR (i)
  108.   END Read;
  109.  
  110.   PROCEDURE ReadBytes
  111.     ( fh : d.FileHandlePtr; VAR x : ARRAY OF SYS.BYTE; n : LONGINT );
  112.     VAR i : LONGINT;
  113.   BEGIN (* ReadBytes *)
  114.     i := d.FRead (fh, x, 1, n)
  115.   END ReadBytes;
  116.  
  117.   PROCEDURE ReadString ( fh : d.FileHandlePtr; VAR x : ARRAY OF CHAR );
  118.     VAR ch : CHAR; i : INTEGER;
  119.   BEGIN (* ReadString *)
  120.     i := 0;
  121.     REPEAT
  122.       Read (fh, ch); x [i] := ch; INC (i)
  123.     UNTIL ch = 0X
  124.   END ReadString;
  125.  
  126.   PROCEDURE ReadBool ( fh : d.FileHandlePtr; VAR x : BOOLEAN );
  127.     VAR i : SHORTINT;
  128.   BEGIN (* ReadBool *)
  129.     Read (fh, i); x := (i # 0)
  130.   END ReadBool;
  131.  
  132. <*$CopyArrays-*>
  133. BEGIN (* LoadPrefs *)
  134.   dir [0] := SYS.ADR ("PROGDIR:");
  135.   dir [1] := SYS.ADR ("ENV:OL");
  136.   dir [2] := NIL;
  137.   IF du.Search (dir, fileName, s) THEN
  138.     pf := d.Open (s, d.oldFile);
  139.     IF pf # NIL THEN
  140.       ReadBytes (pf, tag, 4);
  141.       IF tag = OLPF THEN
  142.         Read (pf, c); ver := ORD (c);
  143.         IF ver >= 1 THEN
  144.           ReadString (pf, SymSearch);
  145.           ReadString (pf, ObjSearch);
  146.           ReadString (pf, WithPath);
  147.           ReadString (pf, ProgPath);
  148.           ReadString (pf, SymExt);
  149.           ReadString (pf, ObjExt);
  150.           ReadString (pf, WithExt);
  151.           ReadString (pf, LinkCmd);
  152.           ReadString (pf, LinkArgs);
  153.           ReadBool (pf, Verbose);
  154.           ReadBool (pf, MakeIcons);
  155.           Read (pf, c); WithFmt := ORD (c);
  156.  
  157.           d.OldClose (pf);
  158.           RETURN TRUE
  159.         ELSE
  160.           d.OldClose (pf);
  161.           RETURN FALSE
  162.         END;
  163.       ELSE
  164.         d.OldClose (pf);
  165.         RETURN FALSE
  166.       END;
  167.     ELSE
  168.       RETURN FALSE
  169.     END;
  170.   ELSE
  171.     RETURN FALSE
  172.   END;
  173. END LoadPrefs;
  174.  
  175. (*------------------------------------*)
  176. PROCEDURE SavePrefs* ( fileName : ARRAY OF CHAR ) : BOOLEAN;
  177.  
  178.   VAR pf : d.FileHandlePtr; tag : LONGINT; i : INTEGER; ver : CHAR;
  179.  
  180.   PROCEDURE Write ( fh : d.FileHandlePtr; x : SYS.BYTE );
  181.     VAR i : LONGINT;
  182.   BEGIN (* Write *)
  183.     i := d.FPutC (fh, ORD (x))
  184.   END Write;
  185.  
  186.   PROCEDURE WriteBytes
  187.     ( fh : d.FileHandlePtr; VAR x : ARRAY OF SYS.BYTE; n : LONGINT );
  188.     VAR i : LONGINT;
  189.   BEGIN (* WriteBytes *)
  190.     i := d.FWrite (fh, x, 1, n)
  191.   END WriteBytes;
  192.  
  193.   PROCEDURE WriteString ( fh : d.FileHandlePtr; x : ARRAY OF CHAR );
  194.   <*$CopyArrays-*>
  195.   BEGIN (* WriteString *)
  196.     WriteBytes (fh, x, str.Length (x)); Write (fh, 0X)
  197.   END WriteString;
  198.  
  199.   PROCEDURE WriteBool ( fh : d.FileHandlePtr; x : BOOLEAN );
  200.     VAR i : SHORTINT;
  201.   BEGIN (* WriteBool *)
  202.     IF x THEN i := 1 ELSE i := 0 END; Write (fh, i)
  203.   END WriteBool;
  204.  
  205. <*$CopyArrays-*>
  206. BEGIN (* SavePrefs *)
  207.   pf := d.Open (fileName, d.newFile);
  208.   IF pf # NIL THEN
  209.     tag := OLPF; WriteBytes (pf, tag, 4);
  210.     Write (pf, CHR (PrefsVersion));
  211.  
  212.     WriteString (pf, SymSearch);
  213.     WriteString (pf, ObjSearch);
  214.     WriteString (pf, WithPath);
  215.     WriteString (pf, ProgPath);
  216.     WriteString (pf, SymExt);
  217.     WriteString (pf, ObjExt);
  218.     WriteString (pf, WithExt);
  219.     WriteString (pf, LinkCmd);
  220.     WriteString (pf, LinkArgs);
  221.     WriteBool (pf, Verbose);
  222.     WriteBool (pf, MakeIcons);
  223.     Write (pf, CHR (WithFmt));
  224.  
  225.     d.OldClose (pf);
  226.     RETURN TRUE
  227.   ELSE
  228.     RETURN FALSE
  229.   END
  230. END SavePrefs;
  231.  
  232. BEGIN (* OLSettings *)
  233.   Init()
  234. END OLSettings.
  235.  
  236. (*************************************************************************
  237.  
  238.   $Log: OLSettings.mod $
  239. # Revision 1.3  1995/01/26  02:07:58  fjc
  240. # - Release 1.5
  241. #
  242. # Revision 1.2  1995/01/09  14:46:16  fjc
  243. # - Removed icon names, Scan and Link from preferences file
  244. #   format.
  245. #
  246. # Revision 1.1  1995/01/06  16:31:16  fjc
  247. # Initial revision
  248. #
  249. *************************************************************************)
  250.  
  251.